package cn.yunyichina.openapi.proxy.config;

import java.io.InputStream;
import java.util.Properties;

/**
 * HttpServer的配置
 *
 * @author zhangkewen
 */
public class HttpServerConfig {

    private static HttpServerConfig config;

    public static HttpServerConfig getConfig() {
        if (config == null) {
            config = new HttpServerConfig();
        }
        return config;
    }

    /* 监听端口 */
    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    private int port;


    /* 是否开启http长连接 */
    private boolean supportkeepalive;

    public boolean getSupportkeepalive() {
        return supportkeepalive;
    }

    public void setSupportkeepalive(boolean supportkeepalive) {
        this.supportkeepalive = supportkeepalive;
    }

    public String getZookeeperurl() {
        return zookeeperurl;
    }

    public void setZookeeperurl(String zookeeperurl) {
        this.zookeeperurl = zookeeperurl;
    }

    private String zookeeperurl;

    private String jdbcUrl;

    public String getJdbcUrl() {
        return jdbcUrl;
    }

    public void setJdbcUrl(String jdbcUrl) {
        this.jdbcUrl = jdbcUrl;
    }

    public String getJdbcDriverclass() {
        return jdbcDriverclass;
    }

    public void setJdbcDriverclass(String jdbcDriverclass) {
        this.jdbcDriverclass = jdbcDriverclass;
    }

    public String getJdbcUsername() {
        return jdbcUsername;
    }

    public void setJdbcUsername(String jdbcUsername) {
        this.jdbcUsername = jdbcUsername;
    }

    public String getJdbcPassword() {
        return jdbcPassword;
    }

    public void setJdbcPassword(String jdbcPassword) {
        this.jdbcPassword = jdbcPassword;
    }

    private String jdbcDriverclass;
    private String jdbcUsername;
    private String jdbcPassword;

    /**
     * 初始化Http服务端配置
     *
     * @throws Exception
     */
    public void initHttpConfig() throws Exception {
        InputStream is = HttpServerConfig.class.getClassLoader().getResourceAsStream("httpserver.properties");
        Properties pro = new Properties();
        pro.load(is);
        this.port = Integer.parseInt(pro.getProperty("httpserver.port"));
        this.supportkeepalive = Boolean.parseBoolean(pro.getProperty("httpserver.supportkeepalive"));
        this.zookeeperurl = pro.getProperty("httpserver.zookeeper");
        this.jdbcDriverclass = pro.getProperty("jdbc.driverClass");
        this.jdbcPassword = pro.getProperty("jdbc.password");
        this.jdbcUrl = pro.getProperty("jdbc.url");
        this.jdbcUsername = pro.getProperty("jdbc.username");
    }

}
